package com.itbomb.tvdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;

public class MainActivity extends AppCompatActivity {

    private String[] imgUrls = new String[]{
            "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1536206479&di=7316bfa65a4f03bb3d9b302e2967bc06&imgtype=jpg&er=1&src=http%3A%2F%2Fimg.juimg.com%2Ftuku%2Fyulantu%2F140222%2F330485-14022210233078.jpg",
            "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535611757740&di=bfe352a98b15bab9919708819c50bba6&imgtype=0&src=http%3A%2F%2Fimgcdn.yuexing.com%2Fstatic%2Fdata%2Ffiles_cz%2Fuser4%2F32%2F801%2F432801%2F20170919%2F09%2F201709192154152234__1000__667.jpeg",
            "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535611757740&di=6082e82054432a1843a377c479f14343&imgtype=0&src=http%3A%2F%2Fstatic.asmag.com.cn%2Fuploadfile%2F2014%2F0526%2F20140526105020266.jpg",
            "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535611757740&di=a336fd4fdec1490b06ac64b844683817&imgtype=0&src=http%3A%2F%2Fpic2.zhimg.com%2Fv2-f6ac126158ca243c980c72975710f540_1200x500.jpg",
            "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535611757740&di=69f67b548d84e3d91c60365b64bfa1c1&imgtype=0&src=http%3A%2F%2Fwww.guandongphoto.com%2Fdata%2Fattachment%2Fforum%2F201808%2F29%2F095133w94tii4zido4p4sf.jpg",
            "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535611757739&di=ec95b73ab38bc967c37bf817b3ff2f83&imgtype=0&src=http%3A%2F%2Fphotos.tuchong.com%2F58102%2Ff%2F4669833.jpg",
            "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535611757739&di=e57b3b215ad301183869cf63f9da95ec&imgtype=0&src=http%3A%2F%2Fphotos.tuchong.com%2F14273%2Ff%2F6299804.jpg",
            "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535611757738&di=d39defc51752fb0440b1be76a443c7fc&imgtype=0&src=http%3A%2F%2Fimg.juimg.com%2Ftuku%2Fyulantu%2F140624%2F330887-140624213G164.jpg",
            "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535611757738&di=ff42db88fe6e0db1d7ff0b6fbb0941e3&imgtype=0&src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20180829%2F4ce2b690c25f42a98b7bc0df7f3f41e4.jpeg",
            "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535611757736&di=e1c9023144a4a88af20802be5f5439b9&imgtype=0&src=http%3A%2F%2Fi1.img.969g.com%2Fpub%2Fimgx2018%2F08%2F23%2F503_151805_51a0c.jpg",
            "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535611757736&di=b7527d0116dc60c32508a159eaeaf9f5&imgtype=0&src=http%3A%2F%2Fimg.juimg.com%2Ftuku%2Fyulantu%2F131226%2F328140-13122622454944.jpg"
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final LinearLayout llIndicator = findViewById(R.id.ll_indicator);

        Gallery3DView gallery3DView = findViewById(R.id.gallery_3d);
        gallery3DView.setUnselectedScale(0.5f);
        // item之间的间隙可以近似认为是ImageView的宽度与缩放比例的乘积的一半
        gallery3DView.setSpacing(-180);
        //设置图片透明度
        gallery3DView.setUnselectedAlpha(1.0f);
        //设置图片饱和度
        gallery3DView.setUnselectedSaturation(0.0f);
        gallery3DView.setMaxRotation(0);
        gallery3DView.setScaleDownGravity(0.4f);
        gallery3DView.setAdapter(new FancyCoverFlowSampleAdapter(imgUrls));
        gallery3DView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                int childCount = llIndicator.getChildCount();
                for (int count = 0; count < childCount; count++) {
                    ImageView imgIndicator = (ImageView) llIndicator.getChildAt(count);
                    if (position == count){
                        imgIndicator.setImageResource(R.drawable.dot_white);
                    }else{
                        imgIndicator.setImageResource(R.drawable.dot_gray);
                    }
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });


        for (int count = 0; count < imgUrls.length; count++) {
            ImageView pointView = new ImageView(this);
            pointView.setPadding(5, 0, 5, 0);
            pointView.setImageResource(R.drawable.dot_gray);
            llIndicator.addView(pointView);
        }
        gallery3DView.setSelection(3, true);
    }
}
